﻿using System;
using System.Collections.Generic;
using System.Web;

namespace WeiSha.Core
{
	// Token: 0x02000027 RID: 39
	public class Skip
	{
		// Token: 0x17000082 RID: 130
		// (get) Token: 0x06000153 RID: 339 RVA: 0x00009CEC File Offset: 0x00007EEC
		public static Skip Get
		{
			get
			{
				return Skip._get;
			}
		}

		// Token: 0x06000154 RID: 340 RVA: 0x00009D04 File Offset: 0x00007F04
		private Skip()
		{
			bool flag = Skip._list == null;
			if (flag)
			{
				this._init();
			}
		}

		// Token: 0x17000083 RID: 131
		// (get) Token: 0x06000155 RID: 341 RVA: 0x00009D2C File Offset: 0x00007F2C
		public static bool Enable
		{
			get
			{
				bool flag = Skip._enable == null;
				if (flag)
				{
					PlatformInfoHandler.SiteInfoHandlerParaNode siteInfoHandlerParaNode = PlatformInfoHandler.Node("Skip");
					Skip._enable = new bool?(siteInfoHandlerParaNode.Attribute("enable") == "true");
				}
				return Skip._enable.Value;
			}
		}

		// Token: 0x06000156 RID: 342 RVA: 0x00009D88 File Offset: 0x00007F88
		private void _init()
		{
			Skip._list = new List<Skip.SkipItem>();
			PlatformInfoHandler.SiteInfoHandlerParaNode siteInfoHandlerParaNode = PlatformInfoHandler.Node("Skip");
			bool flag = siteInfoHandlerParaNode.Attribute("enable") == "true";
			bool flag2 = !flag;
			if (!flag2)
			{
				PlatformInfoHandler.SiteInfoHandlerParaNode[] children = siteInfoHandlerParaNode.Children;
				foreach (PlatformInfoHandler.SiteInfoHandlerParaNode siteInfoHandlerParaNode2 in children)
				{
					bool flag3 = siteInfoHandlerParaNode2.Attribute("enable") != "false";
					if (flag3)
					{
						Skip.SkipItem skipItem = new Skip.SkipItem(siteInfoHandlerParaNode2.Attribute("web"), siteInfoHandlerParaNode2.Attribute("mobile"));
						Skip._list.Add(skipItem);
					}
				}
			}
		}

		// Token: 0x06000157 RID: 343 RVA: 0x00009E3C File Offset: 0x0000803C
		public static string WebToMobi(string url)
		{
			return Skip._toconvert(url, "web", "mobi");
		}

		// Token: 0x06000158 RID: 344 RVA: 0x00009E60 File Offset: 0x00008060
		public static string MobiToWeb(string url)
		{
			return Skip._toconvert(url, "mobi", "web");
		}

		// Token: 0x06000159 RID: 345 RVA: 0x00009E84 File Offset: 0x00008084
		private static string _toconvert(string url, string oldDevice, string newDevice)
		{
			string[] array = url.Split(new char[] { '/' });
			bool flag = false;
			for (int i = 0; i < array.Length; i++)
			{
				bool flag2 = oldDevice.Equals(array[i], StringComparison.OrdinalIgnoreCase);
				if (flag2)
				{
					array[i] = newDevice;
					flag = true;
					break;
				}
			}
			string text = string.Empty;
			for (int j = 0; j < array.Length; j++)
			{
				text += array[j];
				bool flag3 = j < array.Length - 1;
				if (flag3)
				{
					text += "/";
				}
			}
			bool flag4 = !flag;
			if (flag4)
			{
				text += newDevice;
			}
			return text;
		}

		// Token: 0x0600015A RID: 346 RVA: 0x00009F34 File Offset: 0x00008134
		public string forWeb(string path)
		{
			bool flag = Skip._list == null;
			if (flag)
			{
				this._init();
			}
			string text = string.Empty;
			foreach (Skip.SkipItem skipItem in Skip._list)
			{
				bool flag2 = path.Equals(skipItem.Web, StringComparison.CurrentCultureIgnoreCase);
				if (flag2)
				{
					text = skipItem.Mobile;
					break;
				}
			}
			return text;
		}

		// Token: 0x0600015B RID: 347 RVA: 0x00009FC4 File Offset: 0x000081C4
		public string forMoible(string path)
		{
			bool flag = Skip._list == null;
			if (flag)
			{
				this._init();
			}
			string text = string.Empty;
			foreach (Skip.SkipItem skipItem in Skip._list)
			{
				bool flag2 = path.Equals(skipItem.Mobile, StringComparison.CurrentCultureIgnoreCase);
				if (flag2)
				{
					text = skipItem.Web;
					break;
				}
			}
			return text;
		}

		// Token: 0x0600015C RID: 348 RVA: 0x0000A054 File Offset: 0x00008254
		public static string GetUrl()
		{
			HttpContext httpContext = HttpContext.Current;
			string text = ((httpContext.Request.QueryString["skip"] != null) ? httpContext.Request.QueryString["skip"] : "yes");
			bool flag = text != "yes";
			string text2;
			if (flag)
			{
				text2 = string.Empty;
			}
			else
			{
				string path = httpContext.Request.Path;
				string text3 = string.Empty;
				string text4 = httpContext.Request.QueryString.ToString();
				bool flag2 = Skip.Get.isMobilePage();
				bool flag3 = Browser.IsMobile || Browser.IsIPad;
				bool flag4 = flag2 == flag3;
				if (flag4)
				{
					text2 = text3;
				}
				else
				{
					text3 = (flag3 ? Skip.Get.forWeb(path) : Skip.Get.forMoible(path));
					bool flag5 = string.IsNullOrWhiteSpace(text3) || text3.Equals(path, StringComparison.CurrentCultureIgnoreCase);
					if (flag5)
					{
						text3 = string.Empty;
					}
					bool flag6 = !string.IsNullOrWhiteSpace(text3) && !string.IsNullOrWhiteSpace(text4);
					if (flag6)
					{
						text3 = text3 + "?" + text4;
					}
					text2 = text3;
				}
			}
			return text2;
		}

		// Token: 0x0600015D RID: 349 RVA: 0x0000A178 File Offset: 0x00008378
		protected bool isMobilePage()
		{
			HttpContext httpContext = HttpContext.Current;
			bool flag = false;
			string text = "/mobile";
			string absolutePath = httpContext.Request.Url.AbsolutePath;
			bool flag2 = absolutePath.Length >= text.Length;
			if (flag2)
			{
				string text2 = absolutePath.Substring(0, text.Length);
				bool flag3 = text2.ToLower() == text.ToLower();
				if (flag3)
				{
					flag = true;
				}
			}
			return flag;
		}

		// Token: 0x0400005D RID: 93
		private static readonly Skip _get = new Skip();

		// Token: 0x0400005E RID: 94
		private static List<Skip.SkipItem> _list = null;

		// Token: 0x0400005F RID: 95
		private static bool? _enable = null;

		// Token: 0x02000048 RID: 72
		public class SkipItem
		{
			// Token: 0x1700010A RID: 266
			// (get) Token: 0x060002D7 RID: 727 RVA: 0x000138DC File Offset: 0x00011ADC
			// (set) Token: 0x060002D8 RID: 728 RVA: 0x000138E4 File Offset: 0x00011AE4
			public string Web { get; set; }

			// Token: 0x1700010B RID: 267
			// (get) Token: 0x060002D9 RID: 729 RVA: 0x000138ED File Offset: 0x00011AED
			// (set) Token: 0x060002DA RID: 730 RVA: 0x000138F5 File Offset: 0x00011AF5
			public string Mobile { get; set; }

			// Token: 0x060002DB RID: 731 RVA: 0x000138FE File Offset: 0x00011AFE
			public SkipItem(string web, string mobi)
			{
				this.Web = web;
				this.Mobile = mobi;
			}
		}
	}
}
